const OssConf = require('./ali-oss-conf');
const WebpackAliyunOss = require('webpack-aliyun-oss');
const path = require("path");

// 缓存 365 天
const cacheControl = 60 * 60 * 24 * 365;
console.log("cacheControl -->", cacheControl);

// 文档 https://github.com/gp5251/webpack-aliyun-oss
new WebpackAliyunOss({
  from: [
    './**',
    '!./**/*.html',
    // 项目中的文件
    '!./.git/**',
    '!./node_modules/**',
    '!./.gitignore',
    '!./ali-oss-conf.js',
    '!./build.js',
    '!./git-ignore.js',
    '!./LICENSE',
    '!./package.json',
    '!./yarn.lock',
    '!./package-lock.json',
  ],
  // 上传到根路径
  dist: "",
  timeout: 1000 * 60 * 10,
  // 阿里云上传区域
  region: OssConf.region,
  // 上传到哪个bucket
  bucket: OssConf.bucket,
  // 阿里云的授权accessKeyId
  accessKeyId: OssConf.accessKeyId,
  // 阿里云的授权accessKeySecret
  accessKeySecret: OssConf.accessKeySecret,
  // 设置文件头
  setHeaders(filePath) {
    return { 'Cache-Control': `max-age=${cacheControl}` };
  },
  // 定义上传路径
  setOssPath(filePath) {
    const uploadPath = path.relative(__dirname, filePath)
    return uploadPath;
  },
}).apply();

